package com.suredy.app.dm.srv;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import com.suredy.app.dm.model.DmOpLog;
import com.suredy.core.service.BaseSrvWithEntity;

/**
 * 服务类
 * 
 * @author VIVID.G
 * @since 2016-4-1
 * @version v0.1
 */
@Service
public class DmOpLogSrv extends BaseSrvWithEntity<DmOpLog> {

	public DmOpLogSrv() {
		this.addAnDefOrder("time", false);
	}

	@Override
	public DetachedCriteria getDc(DmOpLog t) {
		DetachedCriteria dc = super.getDc(t);

		if (t == null)
			return dc;

		if (t.getType() != null) {
			dc.add(Restrictions.eq("type", t.getType()));
		}
		if (!StringUtils.isBlank(t.getOperator())) {
			dc.add(Restrictions.like("operator", t.getOperator(), MatchMode.ANYWHERE));
		}
		if (t.getStart() != null) {
			dc.add(Restrictions.ge("time", t.getStart()));
		}
		if (t.getEnd() != null) {
			dc.add(Restrictions.le("time", t.getEnd()));
		}

		return dc;
	}

}
